﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Reflection;
using System.Linq;

namespace MoneyBook.Reflection {
    public static class AttributeExtension {

        public static bool AllowMultiple(this Attribute source) {
            if (source == null) {
                throw new ArgumentNullException("source");
            }
            var attrUsage = source.GetType().GetCustomAttributes(typeof(AttributeUsageAttribute), true)
                                .FirstOrDefault() as AttributeUsageAttribute;
            if (attrUsage == null) {
                return false;
            }
            return attrUsage.AllowMultiple;
        }

        public static T GetSingleCustomAttribute<T>(this MemberInfo source, bool inherit) where T : Attribute {
            return source.GetCustomAttributes(typeof(T), inherit).FirstOrDefault() as T;
        }
    }
}
